package com.hua.controller;

import com.hua.common.Response;
import com.hua.domain.CommodityInfo;
import com.hua.domain.domainVo.CommodityDetailVO;
import com.hua.domain.domainVo.CommodityInfoVo;
import com.hua.domain.domainVo.CommodityVo;
import com.hua.service.CommodityInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @program: git
 * @description: 商品信息
 * @author: 黄燕峰
 * @create: 2022-10-19 13:39
 **/
@RestController
@Api("操作商品类")
@RequestMapping("/commodity")
public class CommodityController {
    @Resource
    private CommodityInfoService commodityInfoService;


    @ApiOperation("获取所有商品列表")
    @GetMapping("/getCommodityList")
    public Response<Map<String,List<CommodityInfo>>> getAll() {
        return commodityInfoService.getCommodityList();
    }


    @ApiOperation("商品列表")
    @PostMapping("/getCategoryList")
    public Response<Map<String,List<CommodityVo>>> categoryListOvResponse(){
        return commodityInfoService.getAllCommodityInfoList();
    }

    /**
    * @Description: 获取单个商品的详细信息
    * @Param: Integer id
    * @return:
    * @Author: 黄燕峰
    */
    @ApiOperation("获取单个商品的详细信息")
    @GetMapping("/getCommodityDetail/{id}")
    public Response<CommodityDetailVO> getCommodityDetail(@PathVariable("id") Integer id){
        return commodityInfoService.getCommodityDetail(id);
    }

    /**
     * @author hua
     * @param commodityInfo
     * @return
     */
    @ApiOperation("添加商品")
    @PostMapping("/add")
    public Response<String>insertInfo(@RequestBody CommodityInfoVo commodityInfo){
        return commodityInfoService.insertCategory(commodityInfo);
    }

    /**
     * @author hua
     * @param commodityInfoId
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("删除商品")
    public Response<String> deleteInfoById(@RequestBody CommodityInfo commodityInfoId){
        return commodityInfoService.deleteInfoById(commodityInfoId);
    }

    /**
     * @author hua
     * @param
     * */

     @PostMapping("/update")
     @ApiOperation("修改商品")
    public Response<String> updateInfoById(@RequestBody CommodityInfoVo commodityInfoVo){
        return commodityInfoService.updateInfoById(commodityInfoVo);
    }



    /**
     * @author feng
     * @param
     * */
    @PostMapping("/deleteByIds")
    @ApiOperation("删除所有选择选的商品")
    public Response<String> deleteByIds(@RequestBody List<Integer> ids){
        return commodityInfoService.deleteByIds(ids);
    }

}
